import {
  setStorageToken,
  removeStorageToken,
  getStorageToken,
  setUserInfo,
  getUserINFO
} from '@/utils/storage'
import { getUserInfo } from '@/api/user'
const state = {
  token: getStorageToken(),
  userInfo: getUserINFO()
}

const mutations = {
  setToken(state, payload) {
    state.token = payload
    setStorageToken(payload)
  },
  removeToken(state) {
    state.token = {}

    removeStorageToken()
  },
  setUserInfo(state, payload) {
    state.userInfo = payload
    setUserInfo(payload)
  }
}
const getters = {}
const actions = {
  async getUserInfoAsync(context) {
    const res = await getUserInfo()
    context.commit('setUserInfo', res.data)
  }
}

export default {
  state,
  mutations,
  getters,
  actions,
  namespaced: true
}
